package com.bdqn.t362.order.servlet;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lqm
 * @ClassName ${NAME}
 * @description: TODO
 */
@WebServlet("/SalesSumServlet")
public class SalesSumServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String [] dataArr = new String[7];
        String[] sumArr = new String[7];
        double initAmout = 1000D;
        //获取前7天的日期
        Calendar calendar = Calendar.getInstance();
        for (int i =1; i<8 ; i++ )

        {
            calendar = Calendar.getInstance();
            calendar.set(Calendar.DATE,calendar.get(Calendar.DAY_OF_MONTH)-i);
            dataArr[dataArr.length-i]=calendar.get(Calendar.YEAR)+"-"+(calendar.get(Calendar.MONTH)+1)+"-"+calendar.get(Calendar.DAY_OF_MONTH);

            sumArr[i-1]=String.valueOf(initAmout+i*100);

        }

        Map<Object,Object> resultMap = new HashMap<>();
        resultMap.put("dataArr",dataArr);
        resultMap.put("sumArr",sumArr);
        PrintWriter out = response.getWriter();
        out.print(JSONObject.toJSONString(resultMap));



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
